package ch.fhnw.qualiscan.application.modals;

import ch.fhnw.qualiscan.Config;
import ch.fhnw.qualiscan.application.models.AdminModel;
import ch.fhnw.qualiscan.core.Modal;
import ch.fhnw.qualiscan.core.db.pojos.Survey;
import ch.fhnw.qualiscan.core.libraries.ModalLibrary;
import ch.fhnw.qualiscan.core.libraries.NotificationLibrary;

import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.HorizontalLayout;

import eu.livotov.tpt.i18n.TM;

@SuppressWarnings("serial")
public class DeleteSurvey extends Modal {

	public DeleteSurvey(final Survey currentSurvey) {
		
		setCaption(TM.get("deletesurvey.title", currentSurvey.getTitle()));
		addComponent(textHelper.p(TM.get("deletesurvey.desc", currentSurvey.getTitle())));
		addComponent(textHelper.p(TM.get("deletesurvey.consequences")));
		
		HorizontalLayout buttonWrap = new HorizontalLayout();
		buttonWrap.setSpacing(true);
		buttonWrap.setMargin(true, false, false, false);
		
		Button cancelButton = new Button(TM.get("action.cancel"));
		cancelButton.setIcon(Config.ICON_CANCEL);
		cancelButton.addListener(new Button.ClickListener() {
			public void buttonClick(ClickEvent event) {
				closeModal();
			}
		});
		
		Button deleteButton = new Button(TM.get("action.delete"));
		deleteButton.setIcon(Config.ICON_DELETE);
		deleteButton.addListener(new Button.ClickListener() {
			public void buttonClick(ClickEvent event) {
				AdminModel adminModel = new AdminModel();
				adminModel.deleteSurvey(currentSurvey);
				dataObject.getLoaderLib().setUrl("Dashboard/0");
				NotificationLibrary.showSuccess(TM.get("deletesurvey.deleted"), null);
				closeModal();
			}
		});
		
		buttonWrap.addComponent(deleteButton);
		buttonWrap.addComponent(cancelButton);
		
		addComponent(buttonWrap);
	}
	
}
